<template>
  <div class="container">
    <div>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item>
              <span>查询日期：</span>
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="错误类型：">
              <el-select v-model="form.errTypeValue" placeholder="请选择">
                <el-option
                  v-for="item in form.errTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="分组：">
              <el-select
                v-model="CLIENT_GROUP_NO"
                placeholder="请选择分组"
                @change="groupchange"
              >
                <el-option
                  v-for="(item, index) in groupingList"
                  :value="item.CLIENT_GROUP_NO"
                  :label="item.CLIENT_GROUP_NAME"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      border
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
    >
      <el-table-column prop="VID" label="VID"></el-table-column>
      <el-table-column prop="车牌号" label="车牌号"></el-table-column>
      <el-table-column prop="所属区" label="所属区"></el-table-column>
      <el-table-column prop="所属单位" label="所属单位"></el-table-column>
      <el-table-column prop="车辆类型" label="车辆类型"></el-table-column>
      <el-table-column prop="设备类型" label="设备类型"></el-table-column>
      <el-table-column prop="问题类型" label="问题类型"></el-table-column>
      <el-table-column prop="问题数量" label="问题数量"></el-table-column>
      <el-table-column prop="日期" label="日期"></el-table-column>
      <el-table-column prop="备注" label="备注"></el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleEdit(scope.$index, scope.row)"
            >详情</el-button
          >
          <el-button
            type="text"
            @click="handleDelete(scope.$index, scope.row)"
            style="color: red"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import "@/assets/css/common.css";
import { formatDate } from "@/common/js/date.js";
import export2Excel from "@/utils/exportExcel/index.js";
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10, //    每页的数据
      formInfo: {
        all: "",
        work: "",
        one: "",
        two: "",
        three: "",
      },
      form: {
        roadName: "",
        radioData: "日",
        valueDay: formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: "",
        errTypeList: [
          { label: '全部', value: '' },
          { label: '数据量异常', value: '数据量异常' },
          { label: '中间点无效定位', value: '中间点无效定位' },
          { label: '起始点无效定位', value: '起始点无效定位' },
          { label: '频繁断点', value: '频繁断点' },
          { label: '长时间断点', value: '长时间断点' },
          { label: '频繁跳点', value: '频繁跳点' },
          { label: '长距离跳点', value: '长距离跳点' }
        ],
        errTypeValue: '',
      },
      tableData: [],
      originalData: [],
      exportExcelData: [],
      groupingList: [],
      CLIENT_GROUP_NO: "",
    };
  },
  created () {
    this.getGroupingList();
  },
  methods: {
    // 获得分组列表
    async getGroupingList () {
      var url =
        "Vehicle/GetClinetListForVehicleCheckInfoAA?ClientNo=" + localStorage.getItem("CLIENT_NO"); // zxdata
      let { data } = await this.$Http.get(url);
      this.groupingList = data;
      this.CLIENT_GROUP_NO = data[0].CLIENT_GROUP_NO;
      this.getlistdata();
    },
    async getlistdata () {
      var url =
        "Vehicle/GetVehicleCheckInfoAA?ClientNo=" + this.CLIENT_GROUP_NO +
        "&Date=" + this.form.valueDay + "&ERROR=" + this.form.errTypeValue;
      const { data } = await this.$Http.get(url);
      this.tableData = data;
      if (this.form.roadName != '') this.tableData = this.tableData.filter(item => item.ROAD.includes(this.form.roadName))
    },
    // 导出Excel
    exportExcel () {
      let excelName = "车辆异常查询";
      const tHeader = [
        "VID",
        "车牌号",
        "所属区",
        "所属单位",
        "车辆类型",
        "设备类型",
        "问题类型",
        "问题数量",
        "日期",
        "备注"
      ];
      const filterVal = [
        "VID",
        "车牌号",
        "所属区",
        "所属单位",
        "车辆类型",
        "设备类型",
        "问题类型",
        "问题数量",
        "日期",
        "备注"
      ];
      export2Excel(tHeader, filterVal, this.tableData, excelName);
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize);
    },
    // 删除
    async handleDelete1 (index, row) {
      const confirmResult = await this.$confirm('确定删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)
      if (confirmResult == 'confirm') {
        const params = {
          ID: row.ID,
        }
        const { data } = await this.$Http.get('Role/DeleteRoleInfo', { params })
        if (data.IsSucess) {
          this.$message.success('删除成功')
          this.isVisibleEdit = false
          this.getRoleList()
        }else {
            this.$message.error('删除失败');
          }  
      }else{
        this.$message.info('取消删除')
        this.isVisibleEdit = false
      }
      
    },
  },
};
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>